/*
 * 诚信查询
 * @author EX-XIEYUWEN001
 * Filename:    IntegrityMedicalServiceImpl.java
 * Copyright:   2014 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2014年10月30日
 */
package com.paic.mhis.hcpms.trust.biz.service.impl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.paic.mhis.common.base.dto.PaginationDTO;
import com.paic.mhis.common.base.intergration.dao.CommonDAO;
import com.paic.mhis.common.util.Constants;
import com.paic.mhis.common.util.PageUtil;
import com.paic.mhis.hcpms.trust.biz.service.DoctorIntegrityService;
import com.paic.mhis.hcpms.trust.common.TrustConstants;
import com.paic.mhis.hcpms.trust.intergration.dao.DoctorIntegrityDAO;

@Component("doctorIntegrityService")
public class DoctorIntegrityServiceImpl implements DoctorIntegrityService {

	private static final Logger logger = Logger.getLogger(InsuredMedicalDetailServiceImpl.class);

	@Autowired
	private DoctorIntegrityDAO doctorIntegrityDAO;
	@Autowired
	private CommonDAO commonDAO;

	@Override
	public Map<String, Object> getWarnInfoCount(Map<String, Object> map) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> resultCount = new HashMap<String, Object>();
		List<Map<String, Object>> resultList = null;
		resultList = doctorIntegrityDAO.getWarnInfoCount(map);
		int allCount = 0;
		// 初始化次数0次
		resultCount.put("remind", 0);
		resultCount.put("written", 0);
		resultCount.put("approvaled", 0);
		resultCount.put("interview", 0);
		resultCount.put("others", 0);
		resultCount.put("auditCount", 0);
		resultCount.put("pointCount", 0);
		for (int i = 0; i < resultList.size(); i++) {
			Map<String, Object> tempMap = resultList.get(i);
			BigDecimal tempCount = (BigDecimal) tempMap.get("num");
			String process = (String) tempMap.get("process");
			allCount += tempCount.intValue();
			if (TrustConstants.REMIND.equals(process)) {
				resultCount.put("remind", tempCount);
			} else if (TrustConstants.WRITTEN.equals(process)) {
				resultCount.put("written", tempCount);
			} else if (TrustConstants.APPROVALED.equals(process)) {
				resultCount.put("approvaled", tempCount);
			} else if (TrustConstants.INTERVIEW.equals(process)) {
				resultCount.put("interview", tempCount);
			} else {
				resultCount.put("others", tempCount);
			}

		}
		resultCount.put("allCount", allCount);
		// 稽核次数
		int auditCount = doctorIntegrityDAO.getAuditCount(map);
		resultCount.put("auditCount", auditCount);
		// 一次记分12分次数
		int pointCount = doctorIntegrityDAO.getPointCount(map);
		resultCount.put("pointCount", pointCount);
		resultMap.put("result", resultCount);
		return resultMap;
	}

	public DoctorIntegrityDAO getDoctorIntegrityDAO() {
		return doctorIntegrityDAO;
	}

	public void setDoctorIntegrityDAO(DoctorIntegrityDAO doctorIntegrityDAO) {
		this.doctorIntegrityDAO = doctorIntegrityDAO;
	}

	public Map getIntegrityAuditInfo(Map paramMap) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap = (Map<String, Object>) commonDAO.get("findAuditDetail", paramMap);
		return resultMap;
	}

	public Map integrityAuditList(Map paramMap) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			PaginationDTO pdto = new PaginationDTO();
			pdto.setDoCount(true);// 查询总条数
			pdto.setQueryAll(false);// 不查询所有记录
			pdto.setQueryParams(paramMap);
			pdto.setStart(Integer.parseInt(paramMap.get("start").toString()));
			pdto.setEnd(Integer.parseInt(paramMap.get("limit").toString())
					+ Integer.parseInt(paramMap.get("start").toString()));
			resultMap = commonDAO.queryPage("findAuditList", pdto);
			resultMap.put(Constants.STATE_KEY, Constants.SUCCESS_STATE_VALUE);
			resultMap.put(Constants.MSG_KEY, Constants.SELECT_SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultMap;
	}

	public int getCountMedicalDetailReport(Map paramMap) {

		return doctorIntegrityDAO.getCountMedicalDetailReport(paramMap);
	}

	public List findMedicalDetailReport(int pageSize, int currentPage, Map paramMap) {
		// 如果没有分页值则初始化值
		PageUtil.assemblePageParamObject(pageSize, currentPage, paramMap);

		return doctorIntegrityDAO.findMedicalDetailReport(paramMap);
	}

	@Transactional
	public Map auditCancle(Map paramMap) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		// 修改任务状态
		doctorIntegrityDAO.updateInsuranceTask(paramMap);
		// 逻辑删除审核意见
		doctorIntegrityDAO.updateAuditOpinion(paramMap);
		resultMap.put(Constants.STATE_KEY, Constants.SUCCESS_STATE_VALUE);
		resultMap.put(Constants.MSG_KEY, Constants.SELECT_SUCCESS);
		return resultMap;
	}
}
